//
//  YGBodyDataBLL.m
//  yuanshangyiliao
//
//  Created by icholab on 2021/4/27.
//

#import "YGBodyDataBLL.h"
#import "YGBodyDataModel.h"
#import "CNHTTPManager.h"
#import "YGBodyHistoryModel.h"
@implementation YGBodyDataBLL

+(void)requestServerDetailWithData:(NSString *)age
                               sex:(NSString *)sex
                           stature:(NSString *)stature
                            weight:(NSString *)weight
                           Success:(void (^)(YGBodyDataModel *model))success
                              fail:(void (^)(NSError *error))fail{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic setObject:@([age intValue]) forKey:@"age"];
    [dic setObject:@([sex intValue]) forKey:@"sex"];
    [dic setObject:@([stature intValue]) forKey:@"stature"];
    [dic setObject:@([weight intValue]) forKey:@"weight"];

    [[CNHTTPManager shared]GET:YG_Medical_URL parameters:dic success:^(id responeObj) {
        NSDictionary *data = [responeObj objectForKey:@"data"];
        YGBodyDataModel *model = [[YGBodyDataModel alloc]initWithDictionary:data error:nil];
        if (success && model != nil) {
            success(model);
        }
        } failure:^(NSError *error, NSString *errorDes) {
            if (fail) {
                fail(error);
            }
        }];
}

+(void)requestServerHistorySuccess:(void (^)(NSArray <YGBodyHistoryModel *> *model))success
                              fail:(void (^)(NSError *error))fail{
    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
    [dic fa_setObjectSafe:@(1) forKey:@"page"];
    [dic fa_setObjectSafe:@(100) forKey:@"rows"];

    [[CNHTTPManager shared]GET:YG_HealthDataList_URL parameters:dic success:^(id responeObj) {
        NSArray *data = [responeObj objectForKey:@"data"];
        NSArray *model = [YGBodyHistoryModel arrayOfModelsFromDictionaries:data];
        if (success && model != nil) {
            success(model);
        }
        } failure:^(NSError *error, NSString *errorDes) {
            if (fail) {
                fail(error);
            }
        }];
}
@end
